#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/12/29 9:00
# @Author  : xinyingjie
# @File    : kafkaSend.py
# @Description :
import time

from kafka import KafkaProducer
import json


producer = KafkaProducer(bootstrap_servers="10.102.1.113:9092", key_serializer=str.encode,
                         value_serializer=lambda x: json.dumps(x).encode('utf-8'))

data = {"timestamp": 1703810967478, "startSimuTime": 1703767637087, "simuTime": 441909285, "count": 4, "objs": [{"carId": 9925, "id": 102094, "roadId": 2, "laneCount": 4, "laneNumber": 1, "laneTypeName": "\u673a\u52a8\u8f66\u9053", "typeCode": 1, "angle": 271.51749201377413, "speed": 15.666666666666663, "size": [], "color": "", "x": -1058.8858487314792, "y": 572.8252141369178, "z": 31.149999618530273, "longitude": 121.12618082725328, "latitude": 28.24484147692623, "eulerY": -3.1680778856028713, "eulerZ": -3.1680778856028713, "licenseCode": "null"}, {"carId": 9927, "id": 102095, "roadId": 2, "laneCount": 4, "laneNumber": 2, "laneTypeName": "\u673a\u52a8\u8f66\u9053", "typeCode": 1, "angle": 271.5176107426151, "speed": 18.47222222222221, "size": [], "color": "", "x": -1043.3740127624417, "y": 568.2128358592684, "z": 31.149999618530273, "longitude": 121.12633889180033, "latitude": 28.244799870139968, "eulerY": -3.168079957812063, "eulerZ": -3.168079957812063, "licenseCode": "null"}, {"carId": 9932, "id": 102096, "roadId": 9, "laneCount": 4, "laneNumber": 3, "laneTypeName": "\u673a\u52a8\u8f66\u9053", "typeCode": 1, "angle": 274.6037074810952, "speed": 17.555555555555546, "size": [], "color": "", "x": -931.6512935194401, "y": 558.4954056675533, "z": 31.149999618530273, "longitude": 121.12747731626422, "latitude": 28.244712270013665, "eulerY": -3.2219425069335994, "eulerZ": -3.2219425069335994, "licenseCode": "null"}, {"carId": 9936, "id": 102097, "roadId": 6, "laneCount": 4, "laneNumber": 2, "laneTypeName": "\u673a\u52a8\u8f66\u9053", "typeCode": 1, "angle": 304.7164493931144, "speed": 16.58087454033118, "size": [], "color": "", "x": 1989.7930841828993, "y": -349.45200022080735, "z": 31.149999618530273, "longitude": 121.15724427243678, "latitude": 28.236518351478765, "eulerY": -3.7475090001016262, "eulerZ": -3.7475090001016262, "licenseCode": "null"}]}

while True:
    producer.send("tessng-data", value=data, key="task_id")
    print(data)
    time.sleep(0.1)